//
//  YKSaleItemCell.m
//  YunKang
//
//  Created by leoking870 on 2017/11/1.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKSaleItemCell.h"
#import "YKDashView.h"
@interface YKSaleItemCell ()
@property (weak, nonatomic) IBOutlet UILabel *regionLabel;
@property (weak, nonatomic) IBOutlet UILabel *saleLabel;
@property (weak, nonatomic) IBOutlet UILabel *goldLabel;

@end
@implementation YKSaleItemCell
@dynamic tableViewItem;

- (void)cellLoadSubViews {
    [super cellLoadSubViews];
    if (self.tableViewItem.model.GOODS_NAME) {
        self.regionLabel.tf_weight = 1;
    }
    else {
        self.regionLabel.tf_weight = 1;
    }

    self.saleLabel.tf_weight = 1;
    self.goldLabel.tf_weight = 1;
    
    self.regionLabel.textAlignment = NSTextAlignmentLeft;
    self.saleLabel.textAlignment = NSTextAlignmentCenter;
    self.goldLabel.textAlignment = NSTextAlignmentCenter;
    
    [@[self.regionLabel, self.saleLabel, self.goldLabel] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.top.equalTo(self.contentView.mas_top).offset(11);
    }];
    
    [@[self.regionLabel, self.saleLabel, self.goldLabel] mas_alignWeightlyAlongAxis:MASAxisTypeHorizontal
                                                                                        fixedSpace:@4
                                                                                         leadingTo:self.contentView.mas_leading
                                                                                         leadSpace:13
                                                                                        trailingTo:self.contentView.mas_trailing
                                                                                         tailSpace:13];
    
    YKDashView* dashView = [[YKDashView alloc]init];
    dashView.lineWidth = .5f;
    dashView.lineColor = [UIColor tf_colorWithHexString:@"#d4d4d4"];
    dashView.dashLineLength = 3;
    [self addSubview:dashView];
    [dashView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.trailing.equalTo(self);
        make.height.mas_equalTo(1);
    }];
}

- (void)cellWillAppear {
    [super cellWillAppear];
    if (self.tableViewItem.model.GENERIC_NAM) {
        self.regionLabel.text = self.tableViewItem.model.GENERIC_NAM;
        self.saleLabel.text = self.tableViewItem.model.SALES_NUM;
        self.goldLabel.text = [NSString stringWithFormat:@"%.2f", self.tableViewItem.model.SALES];
    } else if (self.tableViewItem.model.GOODS_NAME) {
        self.regionLabel.text = self.tableViewItem.model.GOODS_NAME;
        self.saleLabel.text = self.tableViewItem.model.SALES_NUM;
        self.goldLabel.text = [NSString stringWithFormat:@"%.2f", self.tableViewItem.model.SALES];
    }
    else if(self.tableViewItem.model.REGION_NAME){
        self.regionLabel.text = self.tableViewItem.model.REGION_NAME;
        self.saleLabel.text = self.tableViewItem.model.SALES_NUM;
        self.goldLabel.text = [NSString stringWithFormat:@"%.2f", self.tableViewItem.model.SALES];
    }
    else if(self.tableViewItem.model.GUEST_NAME){
        self.regionLabel.text = self.tableViewItem.model.GUEST_NAME;
        self.saleLabel.text = self.tableViewItem.model.SALES_NUM;
        self.goldLabel.text = [NSString stringWithFormat:@"%.2f", self.tableViewItem.model.SALES];
    }
}

@end
